package com.jianyun.jyzs.http;



import com.jianyun.jyzs.utils.NetUtil;

import rx.Subscriber;

/**
 * Created by liml on 17/5/24.
 */

public abstract class JsonCallback<T extends Object> extends Subscriber<T>{
    protected abstract void onResponse(T response);
    //    protected abstract void onFail(String msg);
    protected abstract void onException(String msg);

    @Override
    public void onStart() {
        super.onStart();
        if (!NetUtil.isNetworkConnected()){
            onException("请检查网络连接");
            unsubscribe();
        }
    }

    @Override
    public void onCompleted() {

    }

    @Override
    public void onError(Throwable e) {
        e.printStackTrace();
        onException(e.getMessage());
    }

    @Override
    public void onNext(T t) {
        onResponse(t);
    }
}
